<template>
  <div class="app-container">
    <div class="header">
      <div class="word">
        <div class="w1">
          销售管理
        </div>
        <div class="w2">
          在销售管理中你可以查看商品销售的状态，销售编号等基本信息，同时还可以实现查询销售订单，添加销售订单等功能，提供一套可行的销售管理方案
        </div>
        <div class="w2">
          销售管理系统是销售系统中重要的一环,它可以为我们提供销售的信息，为进一步销售做准备
        </div>
      </div>
      <img class="imgDri" src="../../static/300.jpg">
    </div>
    <div class="index">
      <div class="searchHead">
        <el-button type="primary" @click="openForm">新增销售</el-button>
        <el-input v-model="selectInput" placeholder="请输入订单编号" class="searchIuput">
          <el-button slot="append" v-model="searchInf" icon="el-icon-search" @click="searchMes" />
        </el-input>
      </div>
      <el-table :data="dataList" type="" style="width: 100%">
        <el-table-column prop="seller" label="销售商" width="250" />
        <el-table-column prop="productName" label="产品名称" width="180" />
        <el-table-column prop="proudctPrice" label="单价" width="180" />
        <el-table-column prop="productNum" label="销售量" width="180" />
        <el-table-column prop="productQuota" label="销售额" width="180" />
        <el-table-column prop="gmtModified" label="销售时间" width="180" />
        <el-table-column prop="sellStaff" label="销售人员" />
        <el-table-column prop="staffPhone" label="联系方式" />
        <el-table-column fixed="right" label="操作" width="150">
          <template slot-scope="scope">
            <el-button type="text" style="color:#FF8300" @click="trace(scope.row)">溯源</el-button>
            <el-button type="text" @click="openForm(scope.row)">修改</el-button>
            <el-button type="text" style="color:red" @click="deleteHandle(scope.row.id)">删除</el-button>

            <el-dialog
              :modal-append-to-body="false"
              title="提示"
              :visible.sync="dataList[scope.$index].isShowDel"
              width="30%"
            >
              <span>确认要删除此条信息吗？</span>
              <span slot="footer" class="dialog-footer">
                <el-button @click="dataList[scope.$index].isShowDel = false">取 消</el-button>
                <el-button type="primary" @click="deleteHandle(scope.row.id)">确 定</el-button>
              </span>
            </el-dialog>
          </template>
        </el-table-column>
      </el-table>
      <div class="page">
        <el-pagination
          :page-size="5"
          layout="prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
    <SaleForm ref="form" @refresh="load"/>
    <Trace ref="trace" />
  </div>
</template>

<script>
import {getSellPage,deleteSell} from "@/api/plant/sell" 
import SaleForm from "./components/saleForm.vue"
import Trace from  "./components/trace.vue"
export default {
  name: 'CarLogistics',
  components: {
    SaleForm,Trace
  },
  data() {
    return {
      dataList: [],
      dialogTableVisible: false,
      tranceData: 'http://localhost:9527/#/saleAll',
      addMes: {
        'productName': '',
        'productNum': 0,
        'proudctPrice': 0,
        'sellStaff': '',
        'seller': '',
        'staffPhone': ''
      },
      dialogFormVisible: false,
      pageSize: 5,
      pageNum:1,
      total:0,
      searchInf: '',
      selectInput: '',
    }
  },
  async mounted() {
    this.load()
  },
  methods: {
    async deleteHandle(id) {
      deleteSell(id).then((response) => {
        if (response.statusCode == 20000) {
          this.load()
          this.$message({
            message: '删除成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '发生错误，修改失败',
            type: 'warning'
          })
        }
      })
    },
    trace(data) {
      this.$refs.trace.init(data)
    },
    async load() {
      getSellPage({
        pageNum:this.pageNum,
        pageSize:this.pageSize
      }).then((response) => {
        this.dataList = response.data.records
        this.total = response.data.total
      })
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.pageNum = 1
      this.load()
    },
    handleCurrentChange(val) {
      this.pageNum = val
      this.load()
    },
    searchMes() {
      this.load()
    },
    openForm(data){
      this.$refs.form.init(data)
    }
  }
}
</script>

<style lang="scss" scoped>
.qrcode-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header {
  width: 100%;
  height: 350px;
  // border: 1px solid black;
  display: flex;
  margin-bottom: 20px;
  justify-content: space-between;
}

.form {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;

}

.sel {
  width: 310px;
  display: flex;
  // border: 1px solid black;
  justify-content: right;
  align-content: center;
}

.sel2 {
  width: 240px;
}

.page {
  width: 100%;
  display: flex;
  justify-content: right;
}

.imgDri {
  height: 300px;
  width: 400px;
}

.item {
  width: 300px;
}

.in {
  width: 100%;
}

.w1 {
  height: 80px;
  font-size: 25px;
  font-weight: 350;
}

.w2 {
  height: 50px;
  font-size: 15px;
  font-weight: 250;
}

.searchHead {
  display: flex;
  justify-content: space-between;
}

.searchIuput {
  width: 350px;
}

.sel3 {
  width: 100px;
}
</style>
